<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<% String path = request.getContextPath(); request.setCharacterEncoding("UTF-8");
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>">
    <title>合单保单对账查询</title>
    <jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
    <link href="css/calendar.css"  rel="stylesheet" type="text/css" >
    <link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
    <script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
    <script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
    <style type="text/css">
        .sub-title {
            background: none repeat scroll 0 0 #ffffff;
            font-size: 100%;
            font-weight: bold;
            height: 30px;
            line-height: 30px;
            text-indent: 10px;
            width: 100%;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var defaultBranch;//保存默认机构的值
        $(document).ready(function() {
            isReadyIframe();
            defaultDate();
        });

        function isReadyIframe(){
            var iframe = $(window.parent.document).find("#iframe").length;
            if(iframe==0){
                window.location.href="<%=basePath%>index.jsp";
            }
        }

        //“重置”查询条件
        function  resetCriteria(){
            $('#downloadlifePolicyFileForm input[type!="button"]').val("");
            $('#downloadlifePolicyFileForm select[name!="privilegeBranch"]').val("");
            $("#privilegeBranch").val(defaultBranch);//机构置为默认机构
        }

        //点击“查询”
        function queryLifePolicy(pageIndex){
            var downloadFlag = false;
            if(pageIndex == null){
                pageIndex = 1;
            }
            if(pageIndex == -1){
                pageIndex = 1;
                downloadFlag = true;
            }

            var asyncFlag = true;
            if(pageIndex == -1){
                asyncFlag = false;
            }

            if (checkConditions()) {
                var jsonDate = checkConditions()
            } else {
                return false
            }

            jsonDate.pageIndex = pageIndex
            $.openLoading();
            $.ajax({
                url : "<%=path%>/AochuangController/queryAochuangInfo",
                type : 'POST',
                async : asyncFlag,
                dataType:'json',
                data: jsonDate,
                success:function(page){
                    $.closeLoading();
                    if($.validate(page))return;
                    if(page.result == 'noChannelInfo'){
                        //清空表格数据
                        $("#lifePolicyTable").find("tbody").remove();
                        $("#lifePolicyPageDiv").html("");
                        $.message("error", "查询数据为空，请正确填写查询条件和页码。");
                        return;
                    }

                    // 查询数据为空
                    if (page.data.length ===0) {
                        //清空表格数据
                        $("#lifePolicyTable").find("tbody").remove();
                        $("#lifePolicyPageDiv").html("");
                        $.message("error", "查询数据为空，请正确填写查询条件和页码。");
                        return;
                    }

                    var fieldNames = "polno,prem,amount,count,accountTime,agencyName,status2";
                    var queryDetaiButton = "<input class='input_button_2' name='queryDetai' type='button'  onclick='queryDetai($(this))' value='查看订单'/>";

                    var tableContent = creatTable2(fieldNames,page,null,queryDetaiButton);
                    var tableObj = $("#lifePolicyTable");
                    tableObj.find("tbody").remove();
                    tableObj.append(tableContent);

                    var strPage = creatChannelPage(pageIndex,6,page.maxPage,"27");
                    var pageDIV = $("#lifePolicyPageDiv");
                    pageDIV[0].innerHTML="";
                    pageDIV.append(strPage);

                }
            });
        }

        //弹出层表格绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
        function bindradio(){
            $("input[name='prodradio']").click(function(){
                $("input[name='prodradio']").parent().parent().removeClass("table_highlighter");
                $(this).parent().parent().addClass("table_highlighter");
            });
            $("input[name='partnerradio']").click(function(){
                $("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
                $(this).parent().parent().addClass("table_highlighter");
            });
            $("input[name='deptradio']").click(function(){
                $("input[name='deptradio']").parent().parent().removeClass("table_highlighter");
                $(this).parent().parent().addClass("table_highlighter");
            });
        }

        //统一 关闭窗口(传入要关闭DIV的id)
        function closeCurrentDIV(obj){
            $("#"+obj).CloseDiv();
        }
        //日期格式化
        Date.prototype.format = function(format)
        {
            var o = {
                "M+" : this.getMonth()+1, //month
                "d+" : this.getDate(),    //day
                "h+" : this.getHours(),   //hour
                "m+" : this.getMinutes(), //minute
                "s+" : this.getSeconds(), //second
                "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
                "S" : this.getMilliseconds() //millisecond
            }
            if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
                (this.getFullYear()+"").substr(4 - RegExp.$1.length));
            for(var k in o)if(new RegExp("("+ k +")").test(format))
                format = format.replace(RegExp.$1,
                    RegExp.$1.length==1 ? o[k] :
                        ("00"+ o[k]).substr((""+ o[k]).length));
            return format;
        }

        //默认带出最近一个月的信息
        function defaultDate(){
            var begin=new Date();
            var end=new Date();
            new Date(begin.setMonth((new Date().getMonth()-1)));
            var begintime= begin.format("yyyy-MM-dd");
            var endtime=end.format("yyyy-MM-dd");
            $("#tradeBeginTime").val(begintime);
            $("#tradeEndTime").val(endtime);
        }


        // 校验查询条件
        function checkConditions() {
            var polno= $.trim($("#polno").val());//保单号
            var agencyName=  $.trim($("#agencyName").val());//承运人公司名称
            var fileName=  $.trim($("#fileName").val());//订单文件名称
            var tradeBeginTime=  $.trim($("#tradeBeginTime").val());//交易开始日期
            var tradeEndTime=  $.trim($("#tradeEndTime").val());//交易结束日期
            var status2 =$.trim($("#status2").val());//保单状态
            var jsonDate = {
                polno:polno,
                agencyName:agencyName,
                fileName:fileName,
                status2:status2,
                tradeBeginTime:tradeBeginTime,
                tradeEndTime:tradeEndTime
            }
            return jsonDate
        }

        // 日期加减年且格式转换
        function dateAddYear (dateString, yearCount) {
            var newstr = (dateString.substr(0, 4) - yearCount) + dateString.substr(4)
            return new Date(newstr.replace(/-/g, "/")).getTime();
        }

        function queryDetai(obj){
            var polno = obj.parent().parent().children().eq(0).text();
            var data = {polno:polno};
            $.ajax({
                url: "AochuangController/queryOrderDetaiByPolno",
                type: 'GET',
                async: false,
                contentType: "application/json;charset=UTF-8",
                dataType: 'json',
                data: data,
                success: function (data) {
                  var list = data;
                    var th = "<tr><td><strong>订单号</strong></td><td><strong>订单文件名称</strong></td><td><strong>对账状态</strong></td><tr>"
                    $("#fileNamesTable").append(th);
                    for(i=0;i<list.length;i++){
                        var fileName = "";
                        if(null != list[i].fileName){
                            fileName = list[i].fileName;
                        }
                        ;
                        var tr="<tr><td>"+list[i].orderNo+"</td><td>"+fileName+"</td><td>"
                            +list[i].status1+"</td></tr>";
                        $("#fileNamesTable").append(tr);
                    }
                    $("#fileNamesDiv").OpenDiv();
                }
            })
        }

        function closeDivAndClearData(obj){
            $("#fileNamesTable").empty();
            closeCurrentDIV(obj)
        }
    </script>
</head>
<body>
<div class="current">
    <table class="current_table_1">
        <tbody>
        <tr class="f2">
            <td><img src="./images/current_1.jpg"></td>
            <td class="current_table_1_td">
                <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                <span style=" color:#136bab; ">奥创信息
                        <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>对账查询
                      </span>
            </td>
            <td><img src="./images/current_3.jpg"></td>
        </tr>
        </tbody>
    </table>
</div>

<!--查询条件及结果表单 -->
<table border="1" class="table_02" style="height:150px">
    <tr height="50px">
        <td colspan="2" align="center">
            <form method="post" id="downloadlifePolicyFileForm">
                <table border="0" style="margin: 12px auto;">
                    <tr>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">保单号：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input name="polno" id="polno" class="input_text" style="width:130px;" size="25"/>
                        </td>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">承运人公司名称：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input name="agencyName" id="agencyName" class="input_text" style="width:130px;" size="25"/>
                        </td>
                    </tr>
                    <tr>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">交易日期：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input id="tradeBeginTime" name="tradeBeginTime" readonly="readonly" onclick="showCalendar('tradeBeginTime','y-mm-dd');"   class="input_time"/>
                        </td>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">至：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input id="tradeEndTime" name="tradeEndTime" readonly="readonly" onclick="showCalendar('tradeEndTime','y-mm-dd');"  class="input_time"/>
                        </td>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">保单返回状态：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <select class="search_select_1" name="status2" id="status2">
                                <option value="">---请选择---</option>
                                <option value="0">待同步</option>
                                <option value="1">同步成功</option>
                                <option value="2">同步失败</option>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td colspan="6" style="border: 0;padding-top: 5px;padding-right: 70px">
                            <input type="button"  class="input_button_1"  value="查询"    onClick="queryLifePolicy()"/>
                            <input type="button"  class="input_button_1"  value="重置"    onClick="resetCriteria()"/>
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
    <tr>
        <td valign="top">
            <div id="lifePolicyDiv" style="width:98%;margin:5px" >
                <table class="table_02" id="lifePolicyTable">
                    <thead>
                    <tr>
                        <th style="width:18%" nowrap="nowrap">保单号</th>
                        <th style="width:9%" nowrap="nowrap">保费</th>
                        <th style="width:9%" nowrap="nowrap">保额</th>
                        <th style="width:6%" nowrap="nowrap">合并订单数量</th>
                        <th style="width:12%" nowrap="nowrap">交易日期</th>
                        <th style="width:12%" nowrap="nowrap">承运人公司名称</th>
                        <th style="width:12%" nowrap="nowrap">保单返回状态</th>
                        <th style="width:7%" nowrap="nowrap">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
                <div id="lifePolicyPageDiv"  class="page"></div>
            </div>
        </td>
    </tr>
</table>
<div id="fileNamesDiv" style="display: none;width: 40%;height:75%; padding-bottom: 10px;margin-top: -50px;overflow-y:auto;">
    <div class="table_title_div">
        <table class="table_title" style='width:100%;height: 20px;'>
            <tr>
                <td width="10%"></td>
                <td width="80%" id="interfaceName"></td>
                <td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeDivAndClearData('fileNamesDiv')"/></td>
            </tr>
        </table>
    </div>
    <div>
        <ul style="padding-top: 8px;">
            <li style="float: left;  width: 60% "><h4 class="sub-title">订单详情: </h4></li>
        </ul>
        <table id="fileNamesTable" class="table_02" align="center" style="width: 95%;">
        </table>
    </div>


</div>

</body>
</html>
